package com.example.demo.lambda;

import org.junit.jupiter.api.Test;

import java.io.PrintStream;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.function.*;

public class LambdaTest1 {
    @Test
    public void test1() {
        Runnable runnable = () -> {
            System.out.println(" 我是run方法的实现 ");
        };
    }

    @Test
    public void test2() {
        Consumer<String> consumer = (String str) -> {
            System.out.println(" 传入参数是：" + str);
        };
        Consumer<String> consumer1 = System.out::println;
    }

    @Test
    public void test3() {
        HashMap<String, Object> map = new HashMap<>();
        String[] data = {"", ""};
    }

    @Test
    public void test4() {
        Consumer<String> consumer = str -> {
            System.out.println(" 传入参数是：" + str);
        };
        Consumer<String> consumer1 = System.out::println;
    }

    @Test
    public void test5() {
        Comparator<String> consumer = (s1, s2) -> s1.compareTo(s2);
    }

    @Test
    public void test6() {
        // 获取对象
        PrintStream obj = System.out;
        // 引用对象实例方法
        Consumer<String> consumer1 = obj::println;
        HashMap<String, String> map = new HashMap<>();
        IntSupplier intSupplier = map::size;
        System.out.println(intSupplier.getAsInt());
    }

    @Test
    public void test7() {
        Comparator<String> comparator = String::compareTo;
        Comparator<String> comparator1 = (a, b) -> a.compareTo(b);
        comparator.compare("a", "b");
    }

    @Test
    public void test8() {
        Comparator<Integer> comparator = (a, b) -> {
            return Integer.compare(a, b);
        };
        Comparator<Integer> comparator1 = Integer::compare;
        comparator.compare(1, 2);
    }
    @Test
    public void test9(){
        LambdaI<LambdaD> result = new LambdaI<LambdaD>() {
            @Override
            public LambdaD test(LambdaD s1, LambdaD s2,LambdaD s3) {
                return s1.test(s1, s2);
            }
        };
        LambdaI<LambdaD> result1 = LambdaD::test;
    }
    @Test
    public void test10(){
        Supplier<HashMap> supplier = HashMap::new;
        Function<String,TestClass> frmo = TestClass::new;
    }
    class TestClass{
        private String name;
        public TestClass(String name) {
            this.name = name;
        }
    }
    @Test
    public void test11(){
       Function<Integer,Object[]> function = Object[] :: new;
    }
}
@FunctionalInterface
interface LambdaI<T> {
    T test(T s1,T s2,T s3);
}
class LambdaD{
    LambdaD test(LambdaD s1,LambdaD s2){
        return new LambdaD();
    }
}
class Demo{
    @Test
    public void test9(){
        LambdaI<LambdaD> result = new LambdaI<LambdaD>() {
            @Override
            public LambdaD test(LambdaD s1, LambdaD s2,LambdaD s3) {
                return s1.test(s1, s2);
            }
        };
        LambdaI<LambdaD> result1 = LambdaD::test;
    }
}